﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Runda.CMS.Dal;
using System.Data;
using Runda.CMS.Common.Entity;
using Runda.CMS.Common.Utility;
using Runda.CMS.Common.Log;
using log4net;

namespace Runda.CMS.Bll
{
    public class CommonBll : CacheBase
    { 

        public DataTable getDataFromSQL(string sql) {
            return new CommonDal().getSqlData(sql);
        }

        public string getCode(String type)
        {
            CommonDal u = new CommonDal();
            SysAutoCodeRuleEntity entity = u.GetEntity(type);
            if (entity != null)
            {
                if (entity.ResetType == 0)
                    return string.Format(entity.RuleFormat, entity.Seed);
                else
                    return string.Format(entity.RuleFormat, DateTime.Now, entity.Seed);
            }

            return string.Empty;
        }

        public DataTable dddw(string dddwName)
        {
            string sql = "";

            switch (dddwName)
            { 
                case "vendor" :
                    sql = "select distinct Vendor from Cms_Wsm_InstrumentInfo where Vendor is not null order by 1";
                    break;
                case "insurmentcategory":
                    sql = "select categoryGUID,categoryName from Cms_Ctrt_InstrumentCategory where LEFT(categorycode,2) = '02' and isLastLevel = 1 order by categorycode";
                    break;
                case "sales":
                    sql = "select userid,username from cms_sys_user order by username";
                    break;

            }
            return new CommonDal().getSqlData(sql);
        }
 
    }
}
